﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StringFormats
{
    class Book : IFormattable
    {
        public string BookId { get; }
        public string BookName { get; }
        public double Price { get; }
        public string Houston { get; }

        public Book(string bookId, string bookName, double price, string houston)
        {
            BookId = bookId;
            BookName = bookName;
            Price = price;
            Houston = houston;

        }
        public override string ToString() => $"出版号：{BookId} 书名：{BookName} 价格：{Price} 出版社：{Houston}";

        public virtual string ToString(string format) => ToString(format, null);
       
        public string ToString(string format, IFormatProvider formatProvider)
        {
            switch (format)
            {
                case null:
                case "A":
                    return ToString();
                case "Id":
                    return $"出版号：{BookId}";
                case "Name":
                    return $"书名：{BookName}";
                case "NP":
                    return $"书名：{BookName} 价格：{Price}";
                case "H":
                    return $"出版社：{Houston}";
                case "C": return $"出版号：{BookId} 书名：{BookName} 价格：{Price} 出版社：{Houston}";
                default:
                    throw new FormatException($"invalid format string {format}");
            }
        }
    }
}
